//
//  ElevenViewController.m
//  项目二
//
//  Created by rimi on 16/5/17.
//  Copyright © 2016年 objective. All rights reserved.
//

#import "ElevenViewController.h"

@interface ElevenViewController ()
@property(nonatomic,strong)UILabel *label;
@end

@implementation ElevenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"导航控制器";
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUIInterface];
}

- (void)initUIInterface{
    [self.view addSubview:self.label];
    /**自定义导航栏*/
    /**设置背景颜色*/
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    /**设置主色调*/
    self.navigationController.navigationBar.tintColor = [UIColor yellowColor];
    /**设置导航栏字体*/
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor brownColor]}];
    /**自定义返回按钮*/
    [self.navigationController.navigationBar setBackIndicatorImage:[UIImage imageNamed:@"ball副本"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"fruit1"]];
    /**隐藏返回按钮的文本*/
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    
    
    /**登录*/
    UIBarButtonItem *loginItem = [[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(loginItemTT:)];
    self.navigationItem.leftBarButtonItem = loginItem;
    
    UIBarButtonItem *shareItem = [[UIBarButtonItem alloc]initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(shareItemT:)];
    self.navigationItem.rightBarButtonItem = shareItem;
    /**显示工具栏*/
    self.navigationController.toolbarHidden = YES;
    
    /**获取程序的主窗口*/
    //红色视图
//    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
//    redView.backgroundColor = [UIColor redColor];
//    //    [self.view addSubview:redView];
//    //获取程序的主窗口
//    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
//    [keyWindow addSubview:redView];
    
}
- (void)loginItemTT:(UIBarButtonItem *)sender{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"登录" message:@"我要登录" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *queding = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"确定");
    }];
    
    UIAlertAction *quxiao = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }];
    
    UIAlertAction *youyubujue = [UIAlertAction actionWithTitle:@"犹豫不决" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"犹豫不决");
    }];
    
    [alertController addAction:queding];
    [alertController addAction:quxiao];
    [alertController addAction:youyubujue];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

-(void)shareItemT:(UIBarButtonItem *)sender{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"分享" message:@"我的分享" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *tenxuweibi = [UIAlertAction actionWithTitle:@"腾讯微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _label.text = @"腾讯微博";
    }];
    
    UIAlertAction *xinlangweibo = [UIAlertAction actionWithTitle:@"新浪微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _label.text = @"新浪微博";
    }];
    
    UIAlertAction *quxiao = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    [alertController addAction:tenxuweibi];
    [alertController addAction:xinlangweibo];
    [alertController addAction:quxiao];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark -GET
-(UILabel *)label{
    if (!_label) {
        _label = [[UILabel alloc]initWithFrame:CRM(100, 100, 200, 100)];
        _label.tintColor = [UIColor redColor];
        _label.font = [UIFont systemFontOfSize:30];
    }
    return _label;
}
@end
